from numpy import *
from scipy import *
from matplotlib.pyplot import *
from matplotlib import animation
from numpy import save
from numpy import load

def segments(min,max,steps):
    return [i/float(steps)*(max-min)+min for i in range(steps+1)]

#data = genfromtxt('data.csv', unpack=True)

i=array(segments(-8,8,3000))

count=0
for time in segments(0,2*pi/3.0,250): # A full period.
    
    #outfile = open("Z:data" + "%03d" % (count) + ".csv",'w')

    def H(count):
        return transpose(genfromtxt("./data_150/time" + "%06d" % (count) + ".csv", unpack=True, delimiter=','))[:,1]
    count += 1

    #tdata(count)=transpose(data(count))
    #PLOTS
    #for count in range(0,102)
##    if count < 100:
##
##        fig = figure()
##        ax = axes(xlim=(-2, 2), ylim=(-50, 50))
##        points, = ax.plot([], [],'bo', ms=2)

        #xlim(50000,-50000)
        #ylim(500,-500)
        #scatter(i,H(count))
        #savefig("Z:/Desktop/Project/DATA/400image/400image" + "%03d" % (count) + "data.png", bbox_inches=0)
    #show()


    #def H(count):
        #return tdata_count[:,1]



#ANIMATION
# First set up the figure, the axis, and the plot element we want to animate
fig = figure()
ax = axes(xlim=(-10, 10), ylim=(-500000000, 500000000))
points, = ax.plot([], [],'bo', ms=1)

# initialization function: plot the background of each frame
def init():
    points.set_data([], [])
    return points,

# animation function.  This is called sequentially
#for time in segments(0,2*pi/3.0,100):
#for count in range(0,101):
def animate(count):
    x = i#linspace(0, 2, 1000)
    y = H(count)#sin(2 * np.pi * (x - 0.01 * i))
    points.set_data(x, y)
    return points,

# call the animator.  blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=3000, interval=200, blit=True)

# save the animation as an mp4.  This requires ffmpeg or mencoder to be
# installed.  The extra_args ensure that the x264 codec is used, so that
# the video can be embedded in html5.  You may need to adjust this for
# your system: for more information, see
# http://matplotlib.sourceforge.net/api/animation_api.html
#anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
#anim.save('Hamiltonian.mp4', fps=5, codec='mpeg4', clear_temp=True, frame_prefix='_tmp')
show()
